package com.sz.szaiagent.rag;

import jakarta.annotation.Resource;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Vector;

/**
 * 恋爱应用向量存储配置类
 * 该类用于配置基于SimpleVectorStore的向量存储，结合DashScope嵌入模型，提升文档的存储和检索效率。
 */
@Configuration
public class LoveAppVectorStoreConfig {
    @Resource
    private LoveAppDocumentLoader loveAppDocumentLoader;

    /**
     * 创建恋爱应用向量存储实例
     * @param dashscopeEmbeddingModel DashScope嵌入模型，用于文档向量化
     * @return 配置好的SimpleVectorStore实例
     */
    @Bean
    VectorStore loveAppVectorStore(EmbeddingModel dashscopeEmbeddingModel) {
        SimpleVectorStore simpleVectorStore = SimpleVectorStore.builder(dashscopeEmbeddingModel)
                .build(); // 构建SimpleVectorStore实例
        List<Document> documents = loveAppDocumentLoader.loadMarkdowns(); // 加载Markdown文档
        simpleVectorStore.add(documents); // 将文档添加到向量存储
        return simpleVectorStore; // 返回配置好的向量存储实例
    }
}